package com.xujie.infra.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xujie.infra.entity.WeatherDaily;
import com.xujie.infra.entity.WeatherRecords;
import com.xujie.infra.mapper.WeatherDailyMapper;
import com.xujie.infra.mapper.WeatherRecordsMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Xujie
 * @since 2024/12/21 10:48
 **/

@Slf4j
@Service
public class WeatherService {
	@Resource private WeatherDailyMapper weatherDailyMapper;
	@Resource private WeatherRecordsMapper weatherRecordsMapper;

	/**
	 * 获取某一天的天气记录
	 * @param now 日期
	 * @return 天气记录
	 */
	public List<WeatherRecords> getWeekWeatherRecords(DateTime now) {
		DateTime startOfDay = now.withTimeAtStartOfDay();
		DateTime endOfDay = startOfDay.plusDays(8).plusMillis(-1);
		LambdaQueryWrapper<WeatherRecords> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.between(WeatherRecords::getDataDate, startOfDay.toDate(), endOfDay.toDate());
		return weatherRecordsMapper.selectList(queryWrapper);
	}

}
